home *** CD-ROM | disk | FTP | other *** search
- Module SupportFunctions
- ' Raise to the 4th power.
- Function Power4(ByRef x As Double) As Double
- ' This is faster than x^4.
- x = x * x
- Power4 = x * x
- End Function
-
- ' Two overloaded Sum functions
- ' Note that the Overloads keyword is optional
- Overloads Function Sum(ByVal n1 As Long, ByVal n2 As Long) As Long
- Sum = n1 + n2
- Console.WriteLine("The integer version has been invoked.")
- End Function
-
- Overloads Function Sum(ByVal n1 As Single, ByVal n2 As Single) As Single
- Sum = n1 + n2
- Console.WriteLine("The floating point version has been invoked.")
- End Function
-
- ' Set an object to Nothing and clear its Dispose method if possible.
-
- Sub ClearObject(ByRef obj As Object)
- If TypeOf obj Is IDisposable Then
- ' You need an explicit cast if Option Strict is On.
- DirectCast(obj, IDisposable).Dispose()
- End If
- ' Complete the destruction of the object
- obj = Nothing
- End Sub
- End Module
-
- ' This module is used to demonstrate that modules can raise events
-
- Module FileOperations
- Event Notify_CopyFile(ByVal source As String, ByVal destination As String)
- Event Notify_DeleteFile(ByVal filename As String)
-
- Sub CopyFile(ByVal source As String, ByVal destination As String)
- ' Perform the file copy.
- System.IO.File.Copy(source, destination)
- ' Notify that a copy occurred.
- RaiseEvent Notify_CopyFile(source, destination)
- End Sub
-
- Sub DeleteFile(ByVal filename As String)
- ' Perform the file deletion.
- System.IO.File.Delete(filename)
- ' Notify that a deletion occurred.
- RaiseEvent Notify_DeleteFile(filename)
- End Sub
- End Module
-